
#include <boost/lexical_cast.hpp>
#include "jncConvFn.h"

#include <iostream>

char toChar(char* s)
{
  try {
    return boost::lexical_cast<char>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      // TODO: Do something else,like throwing a customize exception
      throw;
    }
}
unsigned char untoChar(char* s)
{
  try{
    return boost::lexical_cast<unsigned char>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
signed char stoChar(char* s)
{
  try{
    return boost::lexical_cast<signed char>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
char* p_toChar(char* s)
{
  try{
    return boost::lexical_cast<char*>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
unsigned char* p_untoChar(char* s)
{
  try{
    return boost::lexical_cast<unsigned char*>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
signed char* p_stoChar(char* s)
{
  try{
    return boost::lexical_cast<signed char*>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
char* a_toChar(char* s)
{
  return p_toChar(s);
}
unsigned char* a_untoChar(char* s)
{
  return p_untoChar(s);
}
signed char* a_stoChar(char* s)
{
  return p_stoChar(s);
}
char** a_p_toChar(char* s)
{
  return new char*(p_toChar(s));
}
unsigned char** a_p_untoChar(char* s)
{
  return new unsigned char*(p_untoChar(s));
}
signed char** a_p_stoChar(char* s)
{
  return new signed char*(p_stoChar(s));
}
short toShort(char* s)
{
  try{
    return boost::lexical_cast<short>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
unsigned short untoShort(char* s)
{
  try{
    return boost::lexical_cast<unsigned short>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
signed short stoShort(char* s)
{
  try{
    return boost::lexical_cast<signed short>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
short* p_toShort(char* s)
{
  return new short(boost::lexical_cast<short>(toShort(s)));
}
unsigned short* p_untoShort(char* s)
{
  return new unsigned short(boost::lexical_cast<unsigned short>(untoShort(s)));
}
signed short* p_stoShort(char* s)
{
  return new signed short(boost::lexical_cast<signed short>(stoShort(s)));
}
short* a_toShort(char* s)
{
  return p_toShort(s);
}
unsigned short* a_untoShort(char* s)
{
  return p_untoShort(s);
}
signed short* a_stoShort(char* s)
{
  return p_stoShort(s);
}
short** a_p_toShort(char* s)
{
  return new short*(p_toShort(s));
}
unsigned short** a_p_untoShort(char* s)
{
  return new unsigned short*(p_untoShort(s));
}
signed short** a_p_stoShort(char* s)
{
  return new signed short*(p_stoShort(s));
}
int toInt(char* s)
{
  try{
    return boost::lexical_cast<int>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
unsigned int untoInt(char* s)
{
  try{
    return boost::lexical_cast<unsigned int>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
signed int stoInt(char* s)
{
  try{
    return boost::lexical_cast<signed int>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
int* p_toInt(char* s)
{
  return new int(boost::lexical_cast<int>(toInt(s)));
}
unsigned int* p_untoInt(char* s)
{
  return new unsigned int(boost::lexical_cast<unsigned int>(untoInt(s)));
}
signed int* p_stoInt(char* s)
{
  return new signed int(boost::lexical_cast<signed int>(stoInt(s)));
}
int* a_toInt(char* s)
{
  return p_toInt(s);
}
unsigned int* a_untoInt(char* s)
{
  return p_untoInt(s);
}
signed int* a_stoInt(char* s)
{
  return p_stoInt(s);
}
int** a_p_toInt(char* s)
{
  return new int*(p_toInt(s));
}
unsigned int** a_p_untoInt(char* s)
{
  return new unsigned int*(p_untoInt(s));
}
signed int** a_p_stoInt(char* s)
{
  return new signed int*(p_stoInt(s));
}
long toLong(char* s)
{
  try{
    return boost::lexical_cast<long>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
unsigned long untoLong(char* s)
{
  try{
    return boost::lexical_cast<unsigned long>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
signed long stoLong(char* s)
{
  try{
    return boost::lexical_cast<signed long>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
long* p_toLong(char* s)
{
  return new long(boost::lexical_cast<long>(toLong(s)));
}
unsigned long* p_untoLong(char* s)
{
  return new unsigned long(boost::lexical_cast<unsigned long>(untoLong(s)));
}
signed long* p_stoLong(char* s)
{
  return new signed long(boost::lexical_cast<signed long>(stoLong(s)));
}
long* a_toLong(char* s)
{
  return p_toLong(s);
}
unsigned long* a_untoLong(char* s)
{
  return p_untoLong(s);
}
signed long* a_stoLong(char* s)
{
  return p_stoLong(s);
}
long** a_p_toLong(char* s)
{
  return new long*(p_toLong(s));
}
unsigned long** a_p_untoLong(char* s)
{
  return new unsigned long*(p_untoLong(s));
}
signed long** a_p_stoLong(char* s)
{
  return new signed long*(p_stoLong(s));
}
bool toBool(char* s)
{
  char* tmp = (char*)(s);
  if(strlen(tmp) == 1)
    switch(*tmp) {
    case '1': return true;
      break;
    case '0': return false;
      break;
    }
  else
    if(std::string(tmp) == std::string("true"))
      return true;
    else if(std::string(tmp) == std::string("false"))
      return false;
  throw boost::bad_lexical_cast();
}
bool* p_toBool(char* s)
{
  return new bool(boost::lexical_cast<bool>(toBool(s)));
}
bool* a_toBool(char* s)
{
  return p_toBool(s);
}
bool** a_p_toBool(char* s)
{
  return new bool*(p_toBool(s));
}
double toDouble(char* s)
{
  try{
    return boost::lexical_cast<double>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
double* p_toDouble(char* s)
{
  return new double(boost::lexical_cast<double>(toDouble(s)));
}
double* a_toDouble(char* s)
{
  return p_toDouble(s);
}
double** a_p_toDouble(char* s)
{
  return new double*(p_toDouble(s));
}
float toFloat(char* s)
{
  try{
    return boost::lexical_cast<float>((char*)s);
  }
  catch(boost::bad_lexical_cast&)
    {
      throw;
    }
}
float* p_toFloat(char* s)
{
  return new float(boost::lexical_cast<float>(toFloat(s)));
}
float* a_toFloat(char* s)
{
  return p_toFloat(s);
}
float** a_p_toFloat(char* s)
{
  return new float*(p_toFloat(s));
}

// CLASSNAME(Token) requires this fn
// void* p_toVoid(char* s)
// { 
//   try {
//     return boost::lexical_cast<void*>((char*)s);
//   }
//   catch(boost::bad_lexical_cast&)
//     {
//       throw;
//     }
// }

